home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / SNNSV32.ZIP / SNNSv3.2 / xgui / sources / ui_print.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-25  |  46.8 KB  |  1,406 lines

  1. /*****************************************************************************
  2.   FILE           : ui_print.c
  3.   SHORTNAME      : print.c
  4.   SNNS VERSION   : 3.2
  5.  
  6.   PURPOSE        : contains routines to print a network on a postscript printer
  7.   NOTES          : not fully implemented
  8.  
  9.   AUTHORS        : Ralf Huebner (C - Code), Tilman Sommer (Postscript Code)
  10.   DATE           : 25.5.1992
  11.  
  12.   CHANGED BY     :
  13.   IDENTIFICATION : @(#)ui_print.c    1.15 3/2/94
  14.   SCCS VERSION   : 1.15
  15.   LAST CHANGE    : 3/2/94
  16.  
  17.              Copyright (c) 1990-1994  SNNS Group, IPVR, Univ. Stuttgart, FRG
  18.              
  19. ******************************************************************************/
  20.  
  21.  
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <malloc.h>            
  25. #include <math.h>            
  26. #include <time.h>            
  27.  
  28. #include <X11/Intrinsic.h>
  29. #include <X11/StringDefs.h>
  30. #include <X11/Shell.h>
  31. #include <X11/Xaw/Simple.h>
  32. #include <X11/Xaw/Box.h>
  33. #include <X11/Xaw/Form.h>
  34. #include <X11/Xaw/Toggle.h>
  35.  
  36. #include "ui.h"
  37. #include "kr_ui.h"
  38.  
  39. #include "ui_setup.h"
  40. #include "ui_xWidgets.h"
  41. #include "ui_display.h"
  42. #include "ui_mainP.h"
  43. #include "ui_confirmer.h"
  44. #include "ui_fileP.h"
  45. #include "ui_color.h"
  46.  
  47. #include "ui_print.ph"
  48.  
  49.  
  50. /*****************************************************************************
  51.   FUNCTION : ui_defaultPrinterValues
  52.  
  53.   PURPOSE  : sets the default printer values
  54.   RETURNS  : void
  55.   NOTES    : change the setup here
  56.  
  57.   UPDATE   :
  58. *****************************************************************************/
  59.  
  60. void ui_defaultPrinterValues (void)
  61.  
  62. {
  63.     ui_prVal.dest            = UI_DEST_FILE;                
  64.     ui_prVal.format          = UI_FORMAT_POSTSCRIPT; 
  65.     ui_prVal.paper           = UI_PAPER_DINA4;   
  66.     ui_prVal.autoScale       = UI_AUTOSCALE_ON;  
  67.     ui_prVal.clip            = UI_CLIP_ON;             
  68.     ui_prVal.color           = UI_COLOR_OFF;             
  69.     ui_prVal.orient          = UI_ORIENTATION_LANDSCAPE;
  70.     ui_prVal.autoUni         = UI_AUTOUNI_ON;  
  71.     ui_prVal.size            = UI_UNITSIZE_VALUE;   
  72.     ui_prVal.shape           = UI_SHAPE_CIRCLE;  
  73.     ui_prVal.text            = UI_TEXT_SOLID;  
  74.     ui_prVal.border          = UI_BORDER_ON;
  75.     ui_prVal.resolution      = 300; 
  76.     ui_prVal.displayToPrint  = 1;
  77.     ui_prVal.borderHoriz     = 10.0;         
  78.     ui_prVal.borderVert      = 10.0;       
  79.     ui_prVal.scaleValX       = 1.0;       
  80.     ui_prVal.scaleValY       = 1.0;       
  81.     ui_prVal.unitGray        = 0.5;
  82.     strcpy (ui_prVal.fileNameStr, "outfile.ps");
  83.     strcpy (ui_prVal.cmdLineStr, "rlp $1 -raw -pr=lw4");
  84. }
  85.  
  86.  
  87. /*****************************************************************************
  88.   FUNCTION : ui_readPrintHeader
  89.  
  90.   PURPOSE  : reads the postscript header into memory
  91.   RETURNS  : void
  92.   NOTES    : this will be changed in the final version
  93.  
  94.   UPDATE   :
  95. *****************************************************************************/
  96.  
  97. static void ui_readPrintHeader (void)
  98.  
  99. {
  100.     FILE *filePtr;
  101.  
  102. #ifndef HEADER_COMPILE
  103.     if ((filePtr = fopen ("psheader05.ps", "r")) == NULL) {
  104.     ui_confirmOk("Error! Can't find Header File\n");
  105.         return;
  106.     }
  107.     fseek (filePtr, 0L, 2);
  108.     headerSize = ftell (filePtr);
  109.     rewind (filePtr);
  110.     if ((psHeader = malloc ((unsigned int) headerSize+1)) == NULL) {
  111.     ui_confirmOk("Error! Can't allocate Memory\n");
  112.         return;
  113.     }
  114.     fread (psHeader, (unsigned int) headerSize, 1, filePtr);
  115.     fclose (filePtr);
  116.     *(psHeader+headerSize) = '\0';
  117. #endif
  118. }
  119.  
  120.  
  121. /*****************************************************************************
  122.   FUNCTION : ui_valueToRGB
  123.  
  124.   PURPOSE  : converts a value to a RGB color tripple
  125.   RETURNS  : void
  126.   NOTES    :
  127.  
  128.   UPDATE   :
  129. *****************************************************************************/
  130.  
  131. static void ui_valueToRGB (float value, float *red, float *green, float *blue)
  132.  
  133. {
  134.     *blue = (1.0 - fabs(value)) / 2.0;
  135.     *red = *green = 0.0;
  136.     if (value > 0) 
  137.        *green = value;
  138.     else
  139.        *red = fabs(value);
  140. }
  141.  
  142.  
  143. /*****************************************************************************
  144.   FUNCTION : ui_printUnit
  145.  
  146.   PURPOSE  : prints a single unit assoziated with a display
  147.   RETURNS  : void
  148.   NOTES    : this routine is taken from the module ui_netGraph.c
  149.  
  150.   UPDATE   :
  151. *****************************************************************************/
  152.  
  153. static void ui_printUnit (struct Ui_DisplayType *displayPtr, int unitNo)
  154.  
  155. {   
  156.     FlintType          value;
  157.     struct PosType     gridPos;
  158.     int                unitSize;
  159.     char               topString[50];
  160.     char               valueString[50];
  161.     float              red, green, blue;
  162.  
  163.     if (NOT ui_isUnitVisibleInDisplay(displayPtr, unitNo))
  164.       return;
  165.  
  166.     if ((displayPtr->setup).unitScaleFactor < 0.00001) 
  167.     (displayPtr->setup).unitScaleFactor = 1.0;
  168.  
  169.     switch ((displayPtr->setup).showValue) {
  170.       case UI_ACTIVATION:
  171.     value = krui_getUnitActivation(unitNo);
  172.     break;
  173.       case UI_INITIAL_ACTIVATION:
  174.     value = krui_getUnitInitialActivation(unitNo);
  175.     break;
  176.       case UI_OUTPUT: 
  177.     value = krui_getUnitOutput(unitNo);
  178.     break;
  179.       case UI_BIAS:
  180.     value = krui_getUnitBias(unitNo);
  181.         break;
  182.     }
  183.     
  184.     value /= (displayPtr->setup).unitScaleFactor;
  185.     if (value > 1.0) value = 1.0;
  186.     if (value < -1.0) value = -1.0;
  187.  
  188.     if (ui_prVal.color == UI_COLOR_ON)
  189.         ui_valueToRGB (value, &red, &green, &blue);
  190.     else
  191.         red = green = blue = ui_prVal.unitGray;
  192.  
  193.     if (value > 0.001)
  194.        unitSize = (int) (value * ms);
  195.     else
  196.        unitSize = 0;
  197.  
  198.     if (ui_prVal.size == UI_UNITSIZE_FIXED)
  199.        unitSize = ms;
  200.  
  201.     krui_getUnitPosition(unitNo, &gridPos);
  202.     
  203.     if ((displayPtr->setup).showTitleFlg) {
  204.        switch ((displayPtr->setup).showTitle) {
  205.            case UI_NUMBER : sprintf(topString,"%d",unitNo);
  206.                             break;
  207.        case UI_ZVALUE : sprintf(topString,"%d",gridPos.z);
  208.                             break;
  209.            case UI_NAME   : if ((krui_getUnitName(unitNo) == NULL) OR
  210.                               (strlen(krui_getUnitName(unitNo)) == 0))
  211.                                 sprintf(topString,"%d",unitNo);
  212.                         else
  213.                              sprintf(topString,"%s", krui_getUnitName(unitNo));
  214.                             break;
  215.            default        : sprintf(topString,"%d",unitNo);
  216.        }
  217.     }
  218.  
  219.     sprintf(valueString,"%4.3f", value);
  220.  
  221.     fprintf (psOutfile, "  (%s) (%s)  %4.3f %4.3f %4.3f  %d %d  %d  du\n",
  222.             topString, valueString, red, green, blue, 
  223.             gridPos.x, gridPos.y, unitSize); 
  224.  
  225. }
  226.  
  227.  
  228. /*****************************************************************************
  229.   FUNCTION : ui_printUnits
  230.  
  231.   PURPOSE  : prints all units assoziated with a display
  232.   RETURNS  : void
  233.   NOTES    : 
  234.  
  235.   UPDATE   : 
  236. *****************************************************************************/
  237.  
  238. static void ui_printUnits (struct Ui_DisplayType *displayPtr)
  239.  
  240. {
  241.     Bool   successful;
  242.     int    unitNo;
  243.  
  244.     successful = ((unitNo = krui_getFirstUnit()) > 0);
  245.     while (successful) {
  246.         ui_printUnit (displayPtr, unitNo);
  247.         successful = ((unitNo = krui_getNextUnit()) > 0);
  248.     }
  249. }
  250.  
  251.  
  252. /*****************************************************************************
  253.   FUNCTION : ui_getNetworkSize
  254.  
  255.   PURPOSE  : gets the size of a network
  256.   RETURNS  : void
  257.   NOTES    : 
  258.  
  259.   UPDATE   :
  260. *****************************************************************************/
  261.  
  262. static void ui_getNetworkSize (int *xmin, int *ymin, int *xmax, int *ymax)
  263.  
  264. {
  265.     struct PosType gridPos;
  266.     Bool   successful;
  267.     int    unitNo;
  268.  
  269.     *xmin = 100000;
  270.     *ymin = 100000;
  271.     *xmax = -100000;
  272.     *ymax = -100000;
  273.     successful = ((unitNo = krui_getFirstUnit()) > 0);
  274.     while (successful) {
  275.         krui_getUnitPosition(unitNo, &gridPos);
  276.         if (gridPos.x < *xmin) *xmin = gridPos.x;
  277.         if (gridPos.y < *ymin) *ymin = gridPos.y;
  278.         if (gridPos.x > *xmax) *xmax = gridPos.x;
  279.         if (gridPos.y > *ymax) *ymax = gridPos.y;
  280.         successful = ((unitNo = krui_getNextUnit()) > 0);
  281.     }
  282. }
  283.     
  284.  
  285. /*****************************************************************************
  286.   FUNCTION : ui_printLink
  287.  
  288.   PURPOSE  : prints a single link assoziated with a display
  289.   RETURNS  : void
  290.   NOTES    : this routine is taken from the module ui_netGraph.c
  291. *****************************************************************************/
  292.  
  293. static void ui_printLink (struct Ui_DisplayType *displayPtr, int sourceNo, 
  294.     int targetNo, FlintType weight)
  295.  
  296. {
  297.     struct PosType   sourceGridPos, targetGridPos;
  298.     Bool             triggered;
  299.     FlintType        weight_true;
  300.     float            red, green, blue;
  301.  
  302.     if (NOT (displayPtr->setup).showLinkFlg)
  303.     return;
  304.     
  305.     if (krui_getUnitSubnetNo(sourceNo) != krui_getUnitSubnetNo(targetNo))
  306.     return;
  307.  
  308.     /* same subnet ... 
  309.  
  310.     if (NOT (ui_isUnitVisibleInDisplay(displayPtr, sourceNo) AND
  311.          ui_isUnitVisibleInDisplay(displayPtr, targetNo)))
  312.       return;
  313.    
  314.        one visible layer containing both units was found */
  315.  
  316.     weight_true = weight;
  317.    
  318.     if (weight >= 0.0) 
  319.     triggered = (weight >= (displayPtr->setup).linkPosTrigger);
  320.     else
  321.     triggered = (weight <= (displayPtr->setup).linkNegTrigger);
  322.  
  323.     if (NOT triggered) return;
  324.  
  325.     krui_getUnitPosition(sourceNo, &sourceGridPos);
  326.     krui_getUnitPosition(targetNo, &targetGridPos);
  327.  
  328.     if (ui_utilAreEqualPositions(sourceGridPos, targetGridPos))
  329.         return;
  330.  
  331.     weight /= (displayPtr->setup).linkScaleFactor;
  332.     if (weight > 1.0) weight = 1.0;
  333.     if (weight < -1.0) weight = -1.0;
  334.  
  335.     if (ui_prVal.color == UI_COLOR_ON)
  336.         ui_valueToRGB (weight, &red, &green, &blue);
  337.     else
  338.         red = green = blue = 0.0;
  339.  
  340.     fprintf (psOutfile, "  (%4.3f)  %d %d  %d %d  %4.3f %4.3f %4.3f  co\n",
  341.              weight_true, sourceGridPos.x, sourceGridPos.y, 
  342.              targetGridPos.x, targetGridPos.y, red, green, blue);
  343.  
  344. }
  345.  
  346.  
  347. /*****************************************************************************
  348.   FUNCTION : ui_printLinks
  349.  
  350.   PURPOSE  : prints all links assoziated with a display
  351.   RETURNS  : void
  352.   NOTES    : 
  353.  
  354.   UPDATE   :
  355. *****************************************************************************/
  356.  
  357. static void ui_printLinks (struct Ui_DisplayType *displayPtr)
  358.  
  359. {
  360.     Bool       successful;
  361.     int        unitNo, predUnit;
  362.     FlintType  weight;
  363.  
  364.     successful = ((unitNo = krui_getFirstUnit()) > 0);
  365.     while (successful) {
  366.  
  367.         (void) krui_setCurrentUnit(unitNo);
  368.  
  369.         if (krui_getUnitInputType(unitNo) == SITES) {
  370.           for (successful = krui_setFirstSite();
  371.              successful; successful = krui_setNextSite()) {
  372.             for(predUnit = krui_getFirstPredUnit(&weight);
  373.             predUnit > 0;
  374.             predUnit = krui_getNextPredUnit(&weight)) {
  375.                 ui_printLink(displayPtr, predUnit, unitNo, weight);
  376.             }
  377.          }
  378.         } else { /* direct links */
  379.          for(predUnit = krui_getFirstPredUnit(&weight);
  380.              predUnit > 0;
  381.              predUnit = krui_getNextPredUnit(&weight)) {
  382.              ui_printLink(displayPtr, predUnit, unitNo, weight);
  383.          }
  384.         }
  385.         successful = ((unitNo = krui_getNextUnit()) > 0);
  386.     }
  387. }
  388.  
  389.  
  390. /*****************************************************************************
  391.   FUNCTION : ui_psBoolean
  392.  
  393.   PURPOSE  : converts a boolean in a string
  394.   RETURNS  : "true" or "false"
  395.   NOTES    : 
  396.  
  397.   UPDATE   :
  398. *****************************************************************************/
  399.  
  400. static char *ui_psBoolean (int toggle)
  401.  
  402. {
  403.     char *s;
  404.  
  405.     s = malloc(6);
  406.     if (toggle)
  407.        strcpy(s, "true");
  408.     else
  409.        strcpy(s, "false");
  410.     return(s);
  411. }
  412.  
  413.  
  414. /*****************************************************************************
  415.   FUNCTION : ui_closeNetworkPannel
  416.  
  417.   PURPOSE  : reads the new values into the ps variables
  418.   RETURNS  : void
  419.   NOTES    : callback from the network setup pannel
  420.  
  421.   UPDATE   :
  422. *****************************************************************************/
  423.  
  424. static void ui_closeNetworkPannel (Widget w, Widget pannel, caddr_t call_data)
  425.  
  426. {
  427.     ulx = ui_xIntFromAsciiWidget(ulxPos);
  428.     uly = ui_xIntFromAsciiWidget(ulyPos);
  429.     lrx = ui_xIntFromAsciiWidget(lrxPos);
  430.     lry = ui_xIntFromAsciiWidget(lryPos);
  431.     FixedUnitSize = ui_psBoolean(!ui_prVal.size);
  432.     ShapeCircle = ui_psBoolean(ui_prVal.shape);
  433.     TransText = ui_psBoolean(ui_prVal.text);
  434.     ShowBorder = ui_psBoolean(!ui_prVal.border);
  435.     ClipOnBorder = ui_psBoolean(!ui_prVal.clip);
  436.     ug = ui_xFloatFromAsciiWidget(fillIntens);
  437.     ui_prVal.displayToPrint = ui_xIntFromAsciiWidget(assDisplay);
  438.  
  439.     XtDestroyWidget (pannel);
  440. }
  441.  
  442.  
  443. /*****************************************************************************
  444.   FUNCTION : ui_transferSettings
  445.  
  446.   PURPOSE  : reads the initial values into the ps variables
  447.   RETURNS  : void
  448.   NOTES    : nessecary if the network pannel is not opened
  449.  
  450.   UPDATE   :
  451. *****************************************************************************/
  452.  
  453. static void ui_transferSettings (void)
  454.  
  455. {
  456.     ulx = networkXmin;
  457.     uly = networkYmin;
  458.     lrx = networkXmax;
  459.     lry = networkYmax;
  460.     FixedUnitSize = ui_psBoolean(!ui_prVal.size);
  461.     ShapeCircle = ui_psBoolean(ui_prVal.shape);
  462.     TransText = ui_psBoolean(ui_prVal.text);
  463.     ShowBorder = ui_psBoolean(!ui_prVal.border);
  464.     ClipOnBorder = ui_psBoolean(!ui_prVal.clip);
  465.     ug = ui_prVal.unitGray;
  466. }
  467.  
  468.  
  469. /*****************************************************************************
  470.   FUNCTION : swap
  471.  
  472.   PURPOSE  : 
  473.   RETURNS  : void
  474.   NOTES    : 
  475.  
  476.   UPDATE   :
  477. *****************************************************************************/
  478.  
  479. static void swap (float *a, float *b)
  480.  
  481. {
  482.     float h;
  483.  
  484.     h = *a;
  485.     *a = *b;
  486.     *b = h;
  487. }   
  488.  
  489.  
  490. /*****************************************************************************
  491.   FUNCTION : ui_setupParams
  492.  
  493.   PURPOSE  : reads the new values into the ps variables
  494.   RETURNS  : void
  495.   NOTES    : called by the printer setup
  496.  
  497.   UPDATE   :
  498. *****************************************************************************/
  499.  
  500. static void ui_setupParams (struct Ui_DisplayType *displayPtr)
  501.  
  502. {
  503.     float frameWidth; 
  504.     float paperWidth, paperHeight, borderVertical, borderHorizontal; /* in points */
  505.     int colIndex;
  506.     time_t t;
  507.     float mm2points = 2.834646;
  508.  
  509.     pw = paperFormats[ui_prVal.paper][0];
  510.     ph = paperFormats[ui_prVal.paper][1];
  511.     LandscapeMode = ui_psBoolean(ui_prVal.orient);
  512.  
  513.     bv = ui_xFloatFromAsciiWidget(borderVert);
  514.     bh = ui_xFloatFromAsciiWidget(borderHoriz);
  515.  
  516.     AutoScale = ui_psBoolean(!ui_prVal.autoScale);
  517.     AutoUni = ui_psBoolean(!ui_prVal.autoUni);
  518.     
  519.     ShowTop = ui_psBoolean((displayPtr->setup).showTitleFlg);
  520.     ShowBottom = ui_psBoolean((displayPtr->setup).showValueFlg);
  521.     Direction = ui_psBoolean((displayPtr->setup).showDirectionFlg);
  522.     ShowWeight = ui_psBoolean((displayPtr->setup).showWeightFlg);
  523.     rs = displayPtr->gridSize;
  524.     ms = ui_unitWidth;   
  525.  
  526.     ImageWidth = (lrx - ulx) * rs + ms;
  527.     ImageHeight = (lry - uly) * rs + ms;
  528.     if ((displayPtr->setup).showTitleFlg)
  529.         ImageHeight += ufs + 1;
  530.     if ((displayPtr->setup).showValueFlg)
  531.         ImageHeight += ufs + 1;
  532.  
  533.     paperWidth = pw * mm2points;
  534.     paperHeight = ph * mm2points;
  535.     borderVertical = bv * mm2points;
  536.     borderHorizontal = bh * mm2points;
  537.     frameWidth = blw * mm2points;
  538.  
  539.     if (ui_prVal.border == UI_BORDER_OFF)
  540.        frameWidth = 0;
  541.    
  542.     if (ui_prVal.orient == UI_ORIENTATION_LANDSCAPE) {
  543.        swap(&ph, &pw);
  544.      }
  545.  
  546.     pw -= 2 * bh;
  547.     ph -= 2 * bv;
  548.  
  549.     isx = isy = 1.0;
  550.     if (ui_prVal.autoScale == UI_AUTOSCALE_ON) {
  551.         isx = (pw * mm2points) / ImageWidth;
  552.         isy = (ph * mm2points) / ImageHeight;
  553.         if (ui_prVal.autoUni == UI_AUTOUNI_ON) {
  554.             isx = min(isx, isy);
  555.             isy = isx;
  556.         }
  557.     } else {
  558.         isx = ui_xFloatFromAsciiWidget(psxScale);
  559.         isy = ui_xFloatFromAsciiWidget(psyScale);
  560.     }
  561.  
  562.     if (ui_prVal.border == UI_BORDER_OFF) {
  563.         if (ui_prVal.orient == UI_ORIENTATION_PORTAIT) {
  564.             bb_xmin = (paperWidth - ImageWidth * isx) / 2;
  565.             bb_ymin = (paperHeight - ImageHeight * isy) / 2;
  566.             bb_xmax = (paperWidth + ImageWidth * isx) / 2;
  567.             bb_ymax = (paperHeight + ImageHeight * isy) / 2;
  568.     } else {
  569.             bb_xmin = (paperWidth - ImageHeight * isy) / 2;
  570.             bb_ymin = (paperHeight - ImageWidth * isx) / 2;
  571.             bb_xmax = (paperWidth + ImageHeight * isy) / 2;
  572.             bb_ymax = (paperHeight + ImageWidth * isx) / 2;
  573.     }
  574.     pw += 2 * bh;
  575.     ph += 2 * bv;
  576.         bv = bb_xmin / mm2points;
  577.         bh = bb_ymin / mm2points;
  578.     pw -= 2 * bh;
  579.     ph -= 2 * bv;
  580.     } else {
  581.         bb_xmin = (ui_prVal.orient ? borderVertical : borderHorizontal) - frameWidth;
  582.         bb_ymin = (ui_prVal.orient ? borderHorizontal : borderVertical) - frameWidth;
  583.         bb_xmax = paperWidth + bb_xmin + 2 * frameWidth;
  584.         bb_ymax = paperHeight + bb_ymin + 2 * frameWidth;
  585.  
  586.     }
  587.  
  588.     if (ui_prVal.color == UI_COLOR_ON) {
  589.         colIndex = (displayPtr->setup).textColorIndex;
  590.         TextRed = ui_editColorRGB[colIndex][0]; 
  591.         TextGreen = ui_editColorRGB[colIndex][1]; 
  592.         TextBlue = ui_editColorRGB[colIndex][2]; 
  593.         colIndex = (displayPtr->setup).backgroundColorIndex;
  594.         BackgroundRed = ui_editColorRGB[colIndex][0]; 
  595.         BackgroundGreen = ui_editColorRGB[colIndex][1]; 
  596.         BackgroundBlue = ui_editColorRGB[colIndex][2];
  597.     } else {
  598.         TextRed = TextGreen = TextBlue = 0.0;
  599.         BackgroundRed = BackgroundGreen = BackgroundBlue = 1.0;
  600.     } 
  601.     
  602.     time(&t);
  603.     timeStr = ctime(&t);
  604. }
  605.  
  606.  
  607. /*****************************************************************************
  608.   FUNCTION : ui_printProlog
  609.  
  610.   PURPOSE  : writes the postscript prolog
  611.   RETURNS  : void
  612.   NOTES    : 
  613.  
  614.   UPDATE   :
  615. *****************************************************************************/
  616.  
  617. static void ui_printProlog (void)
  618.  
  619. {
  620.     fprintf (psOutfile, "%%!PS-Adobe-2.0\n");
  621.     fprintf (psOutfile, "%%%%Copyright (c) 1992 Tilman Sommer\n");
  622.     fprintf (psOutfile, "%%%%Title: SNNS network: %s\n", ui_filenameNET);
  623.     fprintf (psOutfile, "%%%%Creator: SNNS Version 3.1\n");
  624.     fprintf (psOutfile, "%%%%CreationDate: %s", timeStr);
  625.     fprintf (psOutfile, "%%%%Pages: 0\n");
  626. /*
  627.     fprintf (psOutfile, "%%%%BoundingBox: %4.1f %4.1f  %4.1f %4.1f\n",
  628.                          epsX, epsY, epsWidth, epsHeight);
  629. */
  630.     fprintf (psOutfile, "%%%%BoundingBox: %d %d  %d %d\n",
  631.                          (int) (bb_xmin - 0.5), (int) (bb_ymin - 0.5), 
  632.                          (int) (bb_xmax + 0.5), (int) (bb_ymax + 0.5));
  633.     fprintf (psOutfile, "%%%%DocumentFonts: %s\n", fo);
  634.     fprintf (psOutfile, "%%%%EndComments\n\n");
  635.  
  636.     fprintf (psOutfile, "%%%%BeginProcSet: SNNSGeneralSet 1.0 0\n");
  637.     fprintf (psOutfile, "%%Fixed stuff - DON'T CHANGE THIS!\n");
  638.     fprintf (psOutfile, "/inch { 72 mul } bind def\n");
  639.     fprintf (psOutfile, "/cm { 28.34646 mul } bind def\n");
  640.     fprintf (psOutfile, "/mm { 2.834646 mul } bind def\n");
  641.     fprintf (psOutfile, "/lw 72 300 div def\n");
  642.     fprintf (psOutfile, "/min { 2 copy gt { exch } if pop } bind def\n");
  643.     fprintf (psOutfile, "/max { 2 copy lt { exch } if pop } bind def\n");
  644.     fprintf (psOutfile, "/sgn {dup 0 eq {pop 0}{0 gt {1}{-1} ifelse} ifelse} bind def\n");
  645.     fprintf (psOutfile, "%%%%EndProcSet\n");
  646.     fprintf (psOutfile, "\n");
  647. }
  648.  
  649.  
  650. /*****************************************************************************
  651.   FUNCTION : ui_printParams
  652.  
  653.   PURPOSE  : writes the postscript variables
  654.   RETURNS  : void
  655.   NOTES    : 
  656.  
  657.   UPDATE   :
  658. *****************************************************************************/
  659.  
  660. static void ui_printParams (void)
  661.  
  662. {
  663.     fprintf (psOutfile, "%%%%BeginSetup\n");
  664.     fprintf (psOutfile, "%%General Settings\n\n");
  665.     fprintf (psOutfile, "/tt %s def\n", TransText);
  666.     fprintf (psOutfile, "/sb %s def\n", ShowBorder);
  667.     fprintf (psOutfile, "/cab %s def\n", ClipOnBorder);
  668.     fprintf (psOutfile, "/fo /%s def\n", fo);
  669.     fprintf (psOutfile, "/rs %d def\n", rs);
  670.     fprintf (psOutfile, "/ph %.2f mm def\n", ph);
  671.     fprintf (psOutfile, "/pw %.2f mm def\n", pw);
  672.     fprintf (psOutfile, "/bh %.2f mm def\n", bh);
  673.     fprintf (psOutfile, "/bv %.2f mm def\n", bv);
  674.     fprintf (psOutfile, "/blw %.2f mm def\n", blw);
  675.     fprintf (psOutfile, "/LandscapeMode %s def\n\n", LandscapeMode);
  676.  
  677.     fprintf (psOutfile, "/cabb true def\n");
  678. /*
  679.     fprintf (psOutfile, "/bbllx %.1f def\n", epsX);
  680.     fprintf (psOutfile, "/bblly %.1f def\n", epsY);
  681.     fprintf (psOutfile, "/bburx %.1f def\n", epsWidth);
  682.     fprintf (psOutfile, "/bbury %.1f def\n\n", epsHeight);
  683. */
  684.     fprintf (psOutfile, "/bbllx %.1f def\n", bb_xmin);
  685.     fprintf (psOutfile, "/bblly %.1f def\n", bb_ymin);
  686.     fprintf (psOutfile, "/bburx %.1f def\n", bb_xmax);
  687.     fprintf (psOutfile, "/bbury %.1f def\n\n", bb_ymax);
  688.  
  689.     fprintf (psOutfile, "/ulx %d def\n", ulx);
  690.     fprintf (psOutfile, "/uly %d def\n", uly);
  691.     fprintf (psOutfile, "/lrx %d def\n", lrx);
  692.     fprintf (psOutfile, "/lry %d def\n\n", lry);
  693.  
  694.     fprintf (psOutfile, "/ter %.2f def\n", TextRed);
  695.     fprintf (psOutfile, "/teg %.2f def\n", TextGreen);
  696.     fprintf (psOutfile, "/teb %.2f def\n", TextBlue);
  697.     fprintf (psOutfile, "/bgr %.2f def\n", BackgroundRed);
  698.     fprintf (psOutfile, "/bgg %.2f def\n", BackgroundGreen);
  699.     fprintf (psOutfile, "/bgb %.2f def\n\n", BackgroundBlue);
  700.  
  701.     fprintf (psOutfile, "/ms %d def\n", ms);
  702.     fprintf (psOutfile, "/sc %s def\n", ShapeCircle);
  703.     fprintf (psOutfile, "/ufs %d def\n", ufs);
  704.     fprintf (psOutfile, "/sht %s def\n", ShowTop);
  705.     fprintf (psOutfile, "/shb %s def\n", ShowBottom);
  706.     fprintf (psOutfile, "/ulw %.2f def\n", ulw);
  707.  
  708.     fprintf (psOutfile, "/di %s def\n", Direction);
  709.     fprintf (psOutfile, "/sw %s def\n", ShowWeight);
  710.     fprintf (psOutfile, "/wfs %d def\n", wfs);
  711.  
  712.     fprintf (psOutfile, "/iw %.2f def\n", ImageWidth);
  713.     fprintf (psOutfile, "/ih %.2f def\n", ImageHeight);
  714.     fprintf (psOutfile, "/isx %.2f def\n", isx);
  715.     fprintf (psOutfile, "/isy %.2f def\n", isy);
  716.     fprintf (psOutfile, "%%%%EndSetup\n\n");
  717. }
  718.  
  719.  
  720. /*****************************************************************************
  721.   FUNCTION : ui_printProc
  722.  
  723.   PURPOSE  : the main print procedure
  724.   RETURNS  : ui_printProc
  725.   NOTES    : callback for the print button in the printer pannel
  726.  
  727.   UPDATE   :
  728. *****************************************************************************/
  729.  
  730. static void ui_printProc (void)
  731.  
  732. {
  733.     int        ret;
  734.     char       *commandLine, *s;
  735.     char       buf[40];
  736.  
  737.     if ((ui_prVal.displayToPrint > ui_displ_numberOfItems) OR
  738.         (ui_displ_listPtr == NULL)) {
  739.         sprintf (buf, "Error! Display %d is not open\n", ui_prVal.displayToPrint);
  740.     ui_confirmOk(buf);
  741.         return;
  742.     }
  743.     if (ui_prVal.displayToPrint < 1) {
  744.         sprintf (buf, "Error! Display %d doesn't exits \n", ui_prVal.displayToPrint);
  745.     ui_confirmOk(buf);
  746.         return;
  747.     }
  748.          
  749.     displayPrintPtr = ui_displ_listPtr;
  750.     while ((displayPrintPtr->nextPtr != NULL) AND 
  751.            (displayPrintPtr->displayNo != ui_prVal.displayToPrint))
  752.         displayPrintPtr = displayPrintPtr->nextPtr;   
  753. #ifndef HEADER_COMPILE
  754.     ui_readPrintHeader ();
  755. #endif
  756.     if ((fileName = malloc (UI_STR_LEN)) == NULL) {
  757.         ui_confirmOk("Error! Can't allocate Memory\n");
  758.         return;
  759.     }
  760.     if (ui_prVal.dest == UI_DEST_PRINTER) {
  761.        ui_xStringFromAsciiWidget(cmdLine, ui_prVal.cmdLineStr, UI_STR_LEN);
  762.        fileName = tempnam(ui_tmpDir, ui_praefix);
  763.        if (fileName == NULL) {
  764.         ui_confirmOk("Error! Can't print\n");
  765.             return;
  766.        }
  767.        if ((commandLine = malloc (UI_STR_LEN)) == NULL) {
  768.            ui_confirmOk("Error! Can't allocate Memory\n");
  769.            return;
  770.        }
  771.        *commandLine = '\0';
  772.        for (s=ui_prVal.cmdLineStr; *s!='\0'; s++) {
  773.            if ((*s == '$') AND (*(s+1) == '1')) {
  774.                strcat (commandLine, fileName);
  775.                s++;
  776.         } else {
  777.                strncat (commandLine, s, 1);
  778.         }
  779.        }
  780.     } else {
  781.        ui_xStringFromAsciiWidget(cmdLine, fileName, UI_STR_LEN);
  782.     }
  783.  
  784.     if ((psOutfile = fopen (fileName, "w")) == NULL) {
  785.     ui_confirmOk("Error! Can't open outfile\n");
  786.         return;
  787.     }
  788.     ui_setupParams(displayPrintPtr);
  789.     ui_printProlog();
  790.     ui_printParams();
  791.     fprintf (psOutfile, "%s", psHeader);
  792.     fprintf (psOutfile, "\n%%get font\n");
  793.     fprintf (psOutfile, " /fs wfs def\n");
  794.     fprintf (psOutfile, " fo findfont fs scalefont setfont\n\n");
  795.     ui_printLinks(displayPrintPtr);
  796.     fprintf (psOutfile, "\n%%get font\n");
  797.     fprintf (psOutfile, " /fs ufs def\n");
  798.     fprintf (psOutfile, " fo findfont fs scalefont setfont\n\n");
  799.     ui_printUnits(displayPrintPtr);
  800.     fprintf (psOutfile, "\n showpage\n");
  801.     fprintf (psOutfile, "%%%%EndPage\n\n");
  802.     fprintf (psOutfile, "%%%%Trailer\n\n");
  803.     
  804.     fclose (psOutfile);
  805.     free (fileName);
  806.     
  807.     if (ui_prVal.dest == UI_DEST_PRINTER) {
  808.         ret = system(commandLine);
  809.         if (ret != 0)
  810.         ui_confirmOk("Error! Can't print\n");
  811.         free (commandLine);
  812.     }
  813. }
  814.  
  815.  
  816. /*****************************************************************************
  817.   FUNCTION : ui_closePrintPannel
  818.  
  819.   PURPOSE  : closes the printer pannel
  820.   RETURNS  : void
  821.   NOTES    : callback for the done button in the printer pannel
  822.  
  823.   UPDATE   :
  824. *****************************************************************************/
  825.  
  826. static void ui_closePrintPannel (Widget w, Widget pannel, caddr_t call_data)
  827.  
  828. {
  829.     ui_printPannelIsOpen = FALSE;
  830.     XtDestroyWidget (pannel);
  831. }
  832.  
  833.  
  834. /*****************************************************************************
  835.   FUNCTION : ui_setToggles
  836.  
  837.   PURPOSE  : toggles one of the radio button groups
  838.   RETURNS  : void
  839.   NOTES    : sets the toggle variable to the new value
  840.  
  841.   UPDATE   :
  842. *****************************************************************************/
  843.  
  844. static void ui_setToggles (int index, int *new, int max, Widget widgets[])
  845.  
  846. {
  847.    int i;
  848.  
  849.    for(i=0; i<max; i++)
  850.        ui_xSetToggleState(widgets[i], FALSE);
  851.    ui_xSetToggleState(widgets[index], TRUE);
  852.    *new = index;
  853. }
  854.  
  855.  
  856. /*****************************************************************************
  857.   FUNCTION : ui_setCmdLine
  858.  
  859.   PURPOSE  : toggles the first widget in the printer pannel between
  860.              command fine and file name
  861.   RETURNS  : void
  862.   NOTES    : 
  863.  
  864.   UPDATE   :
  865. *****************************************************************************/
  866.  
  867. static void ui_setCmdLine (int toggle)
  868.  
  869. {
  870.     char str1[15], str2[UI_STR_LEN];
  871.     Arg  arg[2];
  872.  
  873.     if (toggle == UI_DEST_PRINTER) {
  874.         sprintf (str1, "%s", "Command Line");
  875.         sprintf (str2, "%s", ui_prVal.cmdLineStr);
  876.     } else {
  877.         sprintf (str1, "%s", "File Name");
  878.         sprintf (str2, "%s", ui_prVal.fileNameStr);
  879.     }
  880.     ui_prVal.dest = toggle;
  881.     XtSetArg(arg[0], XtNlabel, str1);
  882.     XtSetValues(cmdLabel, arg, 1);
  883.     XtSetArg(arg[0], XtNstring, str2);
  884.     XtSetValues(cmdLine, arg, 1);
  885. }
  886.  
  887.  
  888. #ifdef _UNUSED_FUNCTIONS_
  889.  
  890. /*****************************************************************************
  891.   FUNCTION : ui_setFormatProc
  892.   
  893.   PURPOSE  : toggles the format radio button group
  894.   RETURNS  : void
  895.   NOTES    : 
  896.  
  897.   UPDATE   :
  898. *****************************************************************************/
  899.  
  900. static void ui_setFormatProc (Widget w, int value, caddr_t call_data)
  901.  
  902. {
  903.     ui_setToggles(value, &ui_prVal.format, noOfFmtToggles, formatToggle);
  904. }
  905.  
  906. #endif /* _UNUSED_FUNCTIONS_ */
  907.  
  908.  
  909. /*****************************************************************************
  910.   FUNCTION : ui_setDestProc
  911.  
  912.   PURPOSE  : toggles the destination radio button group
  913.   RETURNS  : void
  914.   NOTES    : 
  915.  
  916.   UPDATE   :
  917. *****************************************************************************/
  918.  
  919. static void ui_setDestProc (Widget w, int value, caddr_t call_data)
  920.  
  921. {
  922.     ui_setCmdLine(value);
  923.     ui_setToggles(value, &ui_prVal.dest, noOfDestToggles, destToggle);
  924. }
  925.  
  926.  
  927. /*****************************************************************************
  928.   FUNCTION : ui_setPaperProc
  929.  
  930.   PURPOSE  : toggles the paper radio button group
  931.   RETURNS  : void
  932.   NOTES    : 
  933.  
  934.   UPDATE   :
  935. *****************************************************************************/
  936.  
  937. static void ui_setPaperProc (Widget w, int value, caddr_t call_data)
  938.  
  939. {
  940.     ui_setToggles(value, &ui_prVal.paper, noOfPaperToggles, paperToggle);
  941.     pw = paperFormats[value][0];
  942.     ph = paperFormats[value][1];
  943. }
  944.  
  945.  
  946. /*****************************************************************************
  947.   FUNCTION : ui_setOrientProc
  948.  
  949.   PURPOSE  : toggles the orientation radio button group
  950.   RETURNS  : void
  951.   NOTES    : 
  952.  
  953.   UPDATE   :
  954. *****************************************************************************/
  955.  
  956. static void ui_setOrientProc (Widget w, int value, caddr_t call_data)
  957.  
  958. {
  959.     ui_setToggles(value, &ui_prVal.orient, noOfOrientToggles, orientToggle);
  960. }
  961.  
  962.  
  963. /*****************************************************************************
  964.   FUNCTION : ui_setAutoScaleProc
  965.  
  966.   PURPOSE  : toggles the autoscale radio button group
  967.   RETURNS  : void
  968.   NOTES    : 
  969.  
  970.   UPDATE   :
  971. *****************************************************************************/
  972.  
  973. static void ui_setAutoScaleProc (Widget w, int value, caddr_t call_data)
  974.  
  975. {
  976.     ui_setToggles(value, &ui_prVal.autoScale, noOfAsToggles, autoScaleToggle);
  977. }
  978.  
  979.  
  980. /*****************************************************************************
  981.   FUNCTION : ui_setAutoUniProc
  982.  
  983.   PURPOSE  : toggles the autouni radio button group
  984.   RETURNS  : void
  985.   NOTES    : 
  986.  
  987.   UPDATE   :
  988. *****************************************************************************/
  989.  
  990. static void ui_setAutoUniProc (Widget w, int value, caddr_t call_data)
  991.  
  992. {
  993.     ui_setToggles(value, &ui_prVal.autoUni, noOfAuToggles, autoUniToggle);
  994. }
  995.  
  996.  
  997. /*****************************************************************************
  998.   FUNCTION : ui_setSizeProc
  999.  
  1000.   PURPOSE  : toggles the size radio button group
  1001.   RETURNS  : void
  1002.   NOTES    : 
  1003.  
  1004.   UPDATE   :
  1005. *****************************************************************************/
  1006.  
  1007. static void ui_setSizeProc (Widget w, int value, caddr_t call_data)
  1008.  
  1009. {
  1010.     ui_setToggles(value, &ui_prVal.size, noOfSizeToggles, sizeToggle);
  1011. }
  1012.  
  1013.  
  1014. /*****************************************************************************
  1015.   FUNCTION : ui_setShapeProc
  1016.  
  1017.   PURPOSE  : toggles the shape radio button group
  1018.   RETURNS  : void
  1019.   NOTES    : 
  1020.  
  1021.   UPDATE   :
  1022. *****************************************************************************/
  1023.  
  1024. static void ui_setShapeProc (Widget w, int value, caddr_t call_data)
  1025.  
  1026. {
  1027.     ui_setToggles(value, &ui_prVal.shape, noOfShapeToggles, shapeToggle);
  1028. }
  1029.  
  1030.  
  1031.  
  1032. /*****************************************************************************
  1033.   FUNCTION : ui_setTextProc
  1034.  
  1035.   PURPOSE  : toggles the text radio button group
  1036.   RETURNS  : void
  1037.   NOTES    : 
  1038.  
  1039.   UPDATE   :
  1040. *****************************************************************************/
  1041.  
  1042. static void ui_setTextProc (Widget w, int value, caddr_t call_data)
  1043.  
  1044. {
  1045.     ui_setToggles(value, &ui_prVal.text, noOfTextToggles, textToggle);
  1046. }
  1047.  
  1048.  
  1049. /*****************************************************************************
  1050.   FUNCTION : ui_setBorderProc
  1051.  
  1052.   PURPOSE  : toggles the border radio button group
  1053.   RETURNS  : void
  1054.   NOTES    : 
  1055.  
  1056.   UPDATE   :
  1057. *****************************************************************************/
  1058.  
  1059. static void ui_setBorderProc (Widget w, int value, caddr_t call_data)
  1060.  
  1061. {
  1062.     ui_setToggles(value, &ui_prVal.border, noOfBorderToggles, borderToggle);
  1063. }
  1064.  
  1065.  
  1066. #ifdef _UNUSED_FUNCTIONS_
  1067.  
  1068. /*****************************************************************************
  1069.   FUNCTION : ui_setClipProc
  1070.  
  1071.   PURPOSE  : toggles the clip radio button group
  1072.   RETURNS  : void
  1073.   NOTES    : 
  1074.  
  1075.   UPDATE   :
  1076. *****************************************************************************/
  1077.  
  1078. static void ui_setClipProc (Widget w, int value, caddr_t call_data)
  1079.  
  1080. {
  1081.     ui_setToggles(value, &ui_prVal.clip, noOfClipToggles, clipToggle);
  1082. }
  1083.  
  1084. #endif /* _UNUSED_FUNCTIONS_ */
  1085.  
  1086.  
  1087. /*****************************************************************************
  1088.   FUNCTION : ui_setColorProc
  1089.  
  1090.   PURPOSE  : toggles the color radio button group
  1091.   RETURNS  : void
  1092.   NOTES    : 
  1093.  
  1094.   UPDATE   :
  1095. *****************************************************************************/
  1096.  
  1097. static void ui_setColorProc (Widget w, int value, caddr_t call_data)
  1098.  
  1099. {
  1100.     ui_setToggles(value, &ui_prVal.color, noOfColorToggles, colorToggle);
  1101. }
  1102.  
  1103.  
  1104. /*****************************************************************************
  1105.   FUNCTION : ui_printSetupProc
  1106.  
  1107.   PURPOSE  : creates the network setup pannel
  1108.   RETURNS  : void
  1109.   NOTES    : callback for the networkbutton in the printer pannel
  1110.  
  1111.   UPDATE   :
  1112. *****************************************************************************/
  1113.  
  1114. static void ui_printSetupProc (Widget w, Widget button, caddr_t call_data)
  1115.  
  1116. {
  1117.     int n;
  1118.     Arg arg[10];
  1119.     char buf[20];
  1120.     Position xPos, yPos;
  1121.     Dimension width, height;
  1122.     Widget networkPannel, pannel, border, done, label;
  1123.     Widget label1, label2, label3, label4;
  1124.  
  1125.     n = 0;
  1126.     XtSetArg (arg[n], XtNwidth, &width); n++;
  1127.     XtSetArg (arg[n], XtNheight, &height); n++;
  1128.     XtGetValues (button, arg, (unsigned int) n);
  1129.  
  1130.     XtTranslateCoords (button, (Position) (width / 2), (Position) (height / 2),
  1131.                        &xPos, &yPos);
  1132.  
  1133.     n = 0;
  1134.     XtSetArg(arg[n], XtNx, xPos); n++;
  1135.     XtSetArg(arg[n], XtNy, yPos); n++;
  1136.     networkPannel = XtCreatePopupShell ("network setup", transientShellWidgetClass,
  1137.                                       button, arg, (unsigned int) n);
  1138.  
  1139.     border = XtCreateManagedWidget("border", formWidgetClass,
  1140.                                    networkPannel, NULL, ZERO);
  1141.     pannel = XtCreateManagedWidget("pannel", formWidgetClass, border, NULL, ZERO);
  1142.  
  1143.     done = ui_xCreateButtonItem ("done", border, NULL, pannel);
  1144.     XtAddCallback (done, XtNcallback, (XtCallbackProc) ui_closeNetworkPannel,
  1145.                    (caddr_t) networkPannel);
  1146.     label1 = ui_xCreateLabelItem ("x-min", pannel, ui_fontWidth * 6,
  1147.                                    NULL, NULL);
  1148.     sprintf (buf, "%d", networkXmin);
  1149.     ulxPos = ui_xCreateDialogItem ("", pannel, buf, ui_fontWidth * 7, 
  1150.                                    label1, NULL);
  1151.     label2 = ui_xCreateLabelItem ("y-min", pannel, ui_fontWidth * 6,
  1152.                                    ulxPos, NULL);
  1153.     sprintf (buf, "%d", networkYmin);
  1154.     ulyPos = ui_xCreateDialogItem ("", pannel, buf, ui_fontWidth * 7, 
  1155.                                    label2, NULL);
  1156.     label3 = ui_xCreateLabelItem ("x-max", pannel, ui_fontWidth * 6,
  1157.                                    NULL, label1);
  1158.     sprintf (buf, "%d", networkXmax);
  1159.     lrxPos = ui_xCreateDialogItem ("", pannel, buf, ui_fontWidth * 7, 
  1160.                                    label3, label1);
  1161.     label4 = ui_xCreateLabelItem ("y-max", pannel, ui_fontWidth * 6,
  1162.                                    lrxPos, label1);
  1163.     sprintf (buf, "%d", networkYmax);
  1164.     lryPos = ui_xCreateDialogItem ("", pannel, buf, ui_fontWidth * 7, 
  1165.                                    label4, label1);
  1166.  
  1167.     label = ui_xCreateLabelItem ("Unitsize", pannel, ui_fontWidth * 10,
  1168.                                    NULL, label3); 
  1169.     sizeToggle[0] = ui_xCreateToggleItem ("fixed", pannel, NULL,
  1170.                                     label, label3);
  1171.     XtAddCallback (sizeToggle[0], XtNcallback, (XtCallbackProc) ui_setSizeProc, (caddr_t) UI_UNITSIZE_FIXED);
  1172.     sizeToggle[1] = ui_xCreateToggleItem ("value2", pannel, NULL,
  1173.                                     sizeToggle[0], label3);
  1174.     XtAddCallback (sizeToggle[1], XtNcallback, (XtCallbackProc) ui_setSizeProc, (caddr_t) UI_UNITSIZE_VALUE);
  1175.  
  1176.     label = ui_xCreateLabelItem ("Shape", pannel, ui_fontWidth * 10,
  1177.                                    NULL, sizeToggle[0]); 
  1178.     shapeToggle[0] = ui_xCreateToggleItem ("rectangle", pannel, NULL,
  1179.                                     label, sizeToggle[0]);
  1180.     XtAddCallback (shapeToggle[0], XtNcallback, (XtCallbackProc) ui_setShapeProc, (caddr_t) UI_SHAPE_RECT);
  1181.     shapeToggle[1] = ui_xCreateToggleItem ("circle", pannel, NULL,
  1182.                                     shapeToggle[0], sizeToggle[0]);
  1183.     XtAddCallback (shapeToggle[1], XtNcallback, (XtCallbackProc) ui_setShapeProc, (caddr_t) UI_SHAPE_CIRCLE);
  1184.  
  1185.     label = ui_xCreateLabelItem ("Text", pannel, ui_fontWidth * 10,
  1186.                                    NULL, shapeToggle[0]); 
  1187.     textToggle[0] = ui_xCreateToggleItem ("solid2", pannel, NULL,
  1188.                                     label, shapeToggle[0]);
  1189.     XtAddCallback (textToggle[0], XtNcallback, (XtCallbackProc) ui_setTextProc, (caddr_t) UI_TEXT_SOLID);
  1190.     textToggle[1] = ui_xCreateToggleItem ("trans", pannel, NULL,
  1191.                                     textToggle[0], shapeToggle[0]);
  1192.     XtAddCallback (textToggle[1], XtNcallback, (XtCallbackProc) ui_setTextProc, (caddr_t) UI_TEXT_TRANS);
  1193.  
  1194.     label = ui_xCreateLabelItem ("Border", pannel, ui_fontWidth * 10,
  1195.                                    NULL, textToggle[0]); 
  1196.     borderToggle[0] = ui_xCreateToggleItem ("on", pannel, NULL,
  1197.                                     label, textToggle[0]);
  1198.     XtAddCallback (borderToggle[0], XtNcallback, (XtCallbackProc) ui_setBorderProc, (caddr_t) UI_BORDER_ON);
  1199.     borderToggle[1] = ui_xCreateToggleItem ("off", pannel, NULL,
  1200.                                     borderToggle[0], textToggle[0]);
  1201.     XtAddCallback (borderToggle[1], XtNcallback, (XtCallbackProc) ui_setBorderProc, (caddr_t) UI_BORDER_OFF);
  1202.  
  1203. /*
  1204.     label = ui_xCreateLabelItem ("Clipping", pannel, ui_fontWidth * 10,
  1205.                                    NULL, borderToggle[0]); 
  1206.     clipToggle[0] = ui_xCreateToggleItem ("on", pannel, NULL,
  1207.                                     label, borderToggle[0]);
  1208.     XtAddCallback (clipToggle[0], XtNcallback, (XtCallbackProc) ui_setClipProc, (caddr_t) UI_CLIP_ON);
  1209.     clipToggle[1] = ui_xCreateToggleItem ("off", pannel, NULL,
  1210.                                     clipToggle[0], borderToggle[0]);
  1211.     XtAddCallback (clipToggle[1], XtNcallback, (XtCallbackProc) ui_setClipProc, (caddr_t) UI_CLIP_OFF);
  1212. */
  1213.  
  1214.     label = ui_xCreateLabelItem ("Color", pannel, ui_fontWidth * 10,
  1215.                                    NULL, borderToggle[0]); 
  1216.     colorToggle[0] = ui_xCreateToggleItem ("on", pannel, NULL,
  1217.                                     label, borderToggle[0]);
  1218.     XtAddCallback (colorToggle[0], XtNcallback, (XtCallbackProc) ui_setColorProc, (caddr_t) UI_COLOR_ON);
  1219.     colorToggle[1] = ui_xCreateToggleItem ("off", pannel, NULL,
  1220.                                     colorToggle[0], borderToggle[0]);
  1221.     XtAddCallback (colorToggle[1], XtNcallback, (XtCallbackProc) ui_setColorProc, (caddr_t) UI_COLOR_OFF);
  1222.  
  1223.     label = ui_xCreateLabelItem ("Fill Intens.", pannel, ui_fontWidth * 10,
  1224.                                   NULL, colorToggle[0]); 
  1225.     sprintf (buf, "%.2f", ui_prVal.unitGray);
  1226.     fillIntens = ui_xCreateDialogItem ("", pannel, buf, ui_fontWidth * 7, 
  1227.                                    label, colorToggle[0]);
  1228.  
  1229.     label = ui_xCreateLabelItem ("Display", pannel, ui_fontWidth * 10,
  1230.                                   NULL, fillIntens); 
  1231.     sprintf (buf, "%d", ui_prVal.displayToPrint);
  1232.     assDisplay = ui_xCreateDialogItem ("", pannel, buf, ui_fontWidth * 7, 
  1233.                                    label, fillIntens);
  1234.  
  1235.     ui_checkWindowPosition(networkPannel);
  1236.     XtPopup (networkPannel, XtGrabExclusive);
  1237.     ui_xDontResizeWidget(networkPannel); 
  1238.  
  1239.     ui_setToggles(ui_prVal.border, &ui_prVal.border, noOfBorderToggles, borderToggle);
  1240. /*
  1241.     ui_setToggles(ui_prVal.clip, &ui_prVal.clip, noOfClipToggles, clipToggle);
  1242. */
  1243.     ui_setToggles(ui_prVal.color, &ui_prVal.color, noOfColorToggles, colorToggle);
  1244.     ui_setToggles(ui_prVal.size, &ui_prVal.size, noOfSizeToggles, sizeToggle);
  1245.     ui_setToggles(ui_prVal.shape, &ui_prVal.shape, noOfShapeToggles, shapeToggle);
  1246.     ui_setToggles(ui_prVal.text, &ui_prVal.text, noOfTextToggles, textToggle);
  1247.  
  1248. }
  1249.  
  1250.  
  1251. /*****************************************************************************
  1252.   FUNCTION : u_printNet
  1253.  
  1254.   PURPOSE  : creates the printer setup pannel
  1255.   RETURNS  : void
  1256.   NOTES    : callback for the print item in the the gui menu
  1257.  
  1258.   UPDATE   :
  1259. *****************************************************************************/
  1260.  
  1261. void ui_printNet (void)
  1262.  
  1263. {
  1264.     Widget       printPannel, border, pannel, done, network, print, label;
  1265.     Widget       label1, label2, label3;
  1266.     Arg          arg[25];
  1267.     Cardinal     n;
  1268.     char         buf[UI_STR_LEN];
  1269.     int          labelWidth = 11;
  1270.  
  1271.     if (ui_printPannelIsOpen)
  1272.        return;
  1273.     ui_printPannelIsOpen = TRUE;
  1274.  
  1275.     if (!ui_printDefaultsAreThere) {
  1276.          ui_defaultPrinterValues();
  1277.          ui_printDefaultsAreThere = TRUE;
  1278.     }
  1279.  
  1280.     ui_getNetworkSize (&networkXmin, &networkYmin, &networkXmax, &networkYmax);
  1281.     ui_transferSettings();
  1282.  
  1283.     sprintf(buf, "printer setup");
  1284.     n = 0;
  1285.     printPannel = 
  1286.     XtCreatePopupShell(buf, topLevelShellWidgetClass, ui_toplevel,
  1287.                arg, n);
  1288.     border = XtCreateManagedWidget("border", boxWidgetClass,
  1289.                                    printPannel, NULL, ZERO);
  1290.     pannel = XtCreateManagedWidget("pannel", formWidgetClass, 
  1291.                                    border, NULL, ZERO);
  1292.  
  1293.     print = ui_xCreateButtonItem ("print", border, NULL, NULL);
  1294.     network = ui_xCreateButtonItem ("network", border, print, NULL);
  1295.     done = ui_xCreateButtonItem ("done", border, network, NULL);
  1296.  
  1297.     XtAddCallback (done, XtNcallback, (XtCallbackProc) ui_closePrintPannel,
  1298.                    (caddr_t) printPannel);
  1299.  
  1300.     XtAddCallback (print, XtNcallback, (XtCallbackProc) ui_printProc, NULL);
  1301.     XtAddCallback (network, XtNcallback, (XtCallbackProc) ui_printSetupProc, (caddr_t) network);
  1302.  
  1303.     cmdLabel = ui_xCreateLabelItem ("Command", pannel, ui_fontWidth * labelWidth,
  1304.                                    NULL, NULL); 
  1305.  
  1306.     cmdLine = ui_xCreateDialogItem ("cmd_line", pannel, ui_prVal.cmdLineStr, ui_fontWidth * 40, 
  1307.                                    cmdLabel, NULL);
  1308.  
  1309.     label = ui_xCreateLabelItem ("Destination", pannel, ui_fontWidth * labelWidth,
  1310.                                    NULL, cmdLine); 
  1311.     destToggle[0] = ui_xCreateToggleItem ("printer", pannel, NULL,
  1312.                                     label, cmdLine);
  1313.     XtAddCallback (destToggle[0], XtNcallback, (XtCallbackProc) ui_setDestProc, (caddr_t) UI_DEST_PRINTER);
  1314.     destToggle[1] = ui_xCreateToggleItem ("file", pannel, NULL,
  1315.                                     destToggle[0], cmdLine);
  1316.     XtAddCallback (destToggle[1], XtNcallback, (XtCallbackProc) ui_setDestProc, (caddr_t) UI_DEST_FILE);
  1317.  
  1318. /*
  1319.     label1 = ui_xCreateLabelItem ("    Format", pannel, ui_fontWidth * 10,
  1320.                                    destToggle[1], cmdLine); 
  1321.     formatToggle[0] = ui_xCreateToggleItem ("postscript", pannel, NULL, label1, cmdLine);
  1322.     XtAddCallback (formatToggle[0], XtNcallback, (XtCallbackProc) ui_setFormatProc, (caddr_t) UI_FORMAT_POSTSCRIPT);
  1323.     formatToggle[1] = ui_xCreateToggleItem ("eps", pannel, NULL, formatToggle[0], cmdLine);
  1324.     XtAddCallback (formatToggle[1], XtNcallback, (XtCallbackProc) ui_setFormatProc, (caddr_t) UI_FORMAT_EPSF);
  1325. */
  1326.     label = ui_xCreateLabelItem ("Paper", pannel, ui_fontWidth * labelWidth,
  1327.                                    NULL, destToggle[0]); 
  1328.     paperToggle[0] = ui_xCreateToggleItem ("dina4", pannel, NULL,
  1329.                                     label, destToggle[0]);
  1330.     XtAddCallback (paperToggle[0], XtNcallback, (XtCallbackProc) ui_setPaperProc, (caddr_t) UI_PAPER_DINA4);
  1331.     paperToggle[1] = ui_xCreateToggleItem ("dina3", pannel, NULL,
  1332.                                     paperToggle[0], destToggle[0]);
  1333.     XtAddCallback (paperToggle[1], XtNcallback, (XtCallbackProc) ui_setPaperProc, (caddr_t) UI_PAPER_DINA3);
  1334.     paperToggle[2] = ui_xCreateToggleItem ("usletter", pannel, NULL,
  1335.                                     paperToggle[1], destToggle[0]);
  1336.     XtAddCallback (paperToggle[2], XtNcallback, (XtCallbackProc) ui_setPaperProc, (caddr_t) UI_PAPER_USLETTER);
  1337.  
  1338.  
  1339.     label = ui_xCreateLabelItem ("Orientation", pannel, ui_fontWidth * labelWidth,
  1340.                                    NULL, paperToggle[0]); 
  1341.     orientToggle[0] = ui_xCreateToggleItem ("portrait", pannel, NULL,
  1342.                                     label, paperToggle[0]);
  1343.     XtAddCallback (orientToggle[0], XtNcallback, (XtCallbackProc) ui_setOrientProc, (caddr_t) UI_ORIENTATION_PORTAIT);
  1344.     orientToggle[1] = ui_xCreateToggleItem ("landscape", pannel, NULL,
  1345.                                     orientToggle[0], paperToggle[0]);
  1346.     XtAddCallback (orientToggle[1], XtNcallback, (XtCallbackProc) ui_setOrientProc, (caddr_t) UI_ORIENTATION_LANDSCAPE);
  1347.  
  1348.     label = ui_xCreateLabelItem ("Border (mm)", pannel, ui_fontWidth * labelWidth,
  1349.                                    NULL, orientToggle[0]);
  1350.     label1 = ui_xCreateLabelItem ("horiz", pannel, ui_fontWidth * 7,
  1351.                                    label, orientToggle[0]);
  1352.     sprintf (buf, "%.2f", ui_prVal.borderHoriz); 
  1353.     borderHoriz = ui_xCreateDialogItem ("horiz", pannel, buf, ui_fontWidth * 7, 
  1354.                                    label1, orientToggle[0]);
  1355.     label2 = ui_xCreateLabelItem ("vert", pannel, ui_fontWidth * 7,
  1356.                                    borderHoriz, orientToggle[0]);
  1357.     sprintf (buf, "%.2f", ui_prVal.borderVert); 
  1358.     borderVert = ui_xCreateDialogItem ("vert", pannel, buf, ui_fontWidth * 7, 
  1359.                                    label2, orientToggle[0]);
  1360.  
  1361.     label = ui_xCreateLabelItem ("X-Scale", pannel, ui_fontWidth * labelWidth,
  1362.                                    NULL, label1);
  1363.     sprintf (buf, "%.2f", ui_prVal.scaleValX); 
  1364.     psxScale = ui_xCreateDialogItem ("xscale", pannel, buf, ui_fontWidth * 7, 
  1365.                                    label, label1);
  1366.  
  1367.     label3 = ui_xCreateLabelItem ("   Y-Scale", pannel, ui_fontWidth * 10,
  1368.                                    psxScale, label1);
  1369.     sprintf (buf, "%.2f", ui_prVal.scaleValY); 
  1370.     psyScale = ui_xCreateDialogItem ("yscale", pannel, buf, ui_fontWidth * 7, 
  1371.                                    label3, label1);
  1372.  
  1373.     label = ui_xCreateLabelItem ("AutoScale", pannel, ui_fontWidth * labelWidth, 
  1374.                                    NULL, psxScale); 
  1375.     autoScaleToggle[0] = ui_xCreateToggleItem ("on", pannel, NULL,
  1376.                                     label, psxScale);
  1377.     XtAddCallback (autoScaleToggle[0], XtNcallback, (XtCallbackProc) ui_setAutoScaleProc, (caddr_t) UI_AUTOSCALE_ON);
  1378.     autoScaleToggle[1] = ui_xCreateToggleItem ("off", pannel, NULL,
  1379.                                     autoScaleToggle[0], psxScale);
  1380.     XtAddCallback (autoScaleToggle[1], XtNcallback, (XtCallbackProc) ui_setAutoScaleProc, (caddr_t) UI_AUTOSCALE_OFF);
  1381.  
  1382.     label1 = ui_xCreateLabelItem ("   Aspect", pannel, ui_fontWidth * 8,
  1383.                                    autoScaleToggle[1], psxScale); 
  1384.     autoUniToggle[0] = ui_xCreateToggleItem ("on", pannel, NULL,
  1385.                                     label1, psxScale);
  1386.     XtAddCallback (autoUniToggle[0], XtNcallback, (XtCallbackProc) ui_setAutoUniProc, (caddr_t) UI_AUTOUNI_ON);
  1387.     autoUniToggle[1] = ui_xCreateToggleItem ("off", pannel, NULL,
  1388.                                     autoUniToggle[0], psxScale);
  1389.     XtAddCallback (autoUniToggle[1], XtNcallback, (XtCallbackProc) ui_setAutoUniProc, (caddr_t) UI_AUTOUNI_OFF);
  1390.  
  1391.     ui_checkWindowPosition(printPannel);
  1392.     XtPopup (printPannel, XtGrabNone);
  1393.     ui_xDontResizeWidget(printPannel); 
  1394.  
  1395.     ui_setCmdLine(ui_prVal.dest);
  1396.     ui_setToggles(ui_prVal.dest, &ui_prVal.dest, noOfDestToggles, destToggle);
  1397. /*
  1398.     ui_setToggles(ui_prVal.format, &ui_prVal.format, noOfFmtToggles, formatToggle);
  1399. */
  1400.     ui_setToggles(ui_prVal.paper, &ui_prVal.paper, noOfPaperToggles, paperToggle); 
  1401.     ui_setToggles(ui_prVal.autoScale, &ui_prVal.autoScale, noOfAsToggles, autoScaleToggle);
  1402.     ui_setToggles(ui_prVal.autoUni, &ui_prVal.autoUni, noOfAuToggles, autoUniToggle);
  1403.     ui_setToggles(ui_prVal.orient, &ui_prVal.orient, noOfOrientToggles, orientToggle);
  1404. }
  1405.  
  1406.